var infowindow;
/*关于地图的操作*/	
var tzMap = {
	map:null,
	//其实地图初始化相关
	init:function(map){
		this.map = map;
		//为地图注册click事件获取鼠标点击出的经纬度坐标,并且同时打标记
		var clickEventListener = this.map.on('click', function(e) {
			var cicon = $("#cicon").val();
			tzMap.marker(e.lnglat.getLng(), e.lnglat.getLat(),cicon);
			$("#gw").val(e.lnglat.getLng()+","+e.lnglat.getLat());
			//tzMap.dialog(e.lnglat.getLng(), e.lnglat.getLat());
		});
		
		this.map.plugin(["AMap.ToolBar"], function() {
			map.addControl(new AMap.ToolBar());
		});
		
		if(location.href.indexOf('&guide=1')!==-1){
			map.setStatus({scrollWheel:false})
		}
		
	},
	//城市切换
	change:function(city){
		this.map.setCity(city);
	},
		//雪碧图(合成图)的方式切换标记，
	marker:function(gd,wd,icon,opid,callback){
		var thisMap = this.map;
		var marker = new AMap.Marker({ //添加自定义点标记
			map: thisMap,
			position: [gd, wd], //基点位置
			offset: new AMap.Pixel(-17, -52), //相对于基点的偏移位置
			draggable: false,  //是否可拖动
			content: '<span class="mp micon '+icon+'"></span>'   //自定义点标记覆盖物内容
		});
		
		//标记绑定点击事件，打开窗口
		AMap.event.addListener(marker, 'click', function() {
			var dialog = tzMap.markDialog(opid,thisMap,marker.getPosition());
//			dialog.open(thisMap, marker.getPosition());
		});
		
		if(callback)callback.call(thisMap,tzMap,marker);
	},
	//标记物窗口
	markDialog:function(opid,map,Position){
		$("#panel").html('');
		var template;
		
		if(isNotEmpty(opid)){
			$.ajax({
				type:"post",
				url:"/hotelDetail",
				data:{hotelId:opid},
				success:function(data){
					if(data){
						var json =data;
						console.log(JSON.stringify(json));
						template  = "<div class='hotel'>"+
						"		<div class='h_pic'>"+
						"			<img src='"+json.img+"' alt='' width='300' height='200' />"+
						"		</div>"+
						"		<div class='h_info'>"+
						"			<div class='h_left'>"+
						"				<p class='h_title'>"+
						"					<a href='#'><i class='iconfont icon-iconhottitle'></i>&nbsp;&nbsp;"+json.name+"</a>"+
						"				</p>"+
						"				<p class='h_level'>"+json.level+"<span></span></p>"+
						"			</div>"+
						"			<div class='h_right'>"+
						"				<div class='h_address'><i class='iconfont icon-ditu-dibiao'></i>"+json.address+"</div>"+
						"				<div><i class='iconfont icon-bodadianhua'></i>&nbsp;&nbsp;<a href='tel:'"+json.telephone+"'>"+json.telephone+"</a></div>"+
						"			</div>"+
						"			<div class='clear'></div>"+
						"		</div>"+
						"		<a href='javascript:void(0);'  onclick='tzMap.bus("+lon+","+lat+","+json.gd+","+json.wd+")' class='h_pay'>去这里</a>"+
						"	</div>";
						
						
						//窗口对象初始化
						infowindow = new AMap.InfoWindow({
							 content: template,
							 offset: new AMap.Pixel(-4, -50),
							 size:new AMap.Size(0,0)
						});
						//打开窗口
						infowindow.open(map,Position);
						
					}
				}
			});
		
		}
		
		
	},
	//经纬度窗口
	dialog:function(gd,wd){
		 infowindow = new AMap.InfoWindow({
			 content: '<h3>高德地图</h1><div>高德是中国领先的数字地图内容、导航和位置服务解决方案提供商。</div>',
			 offset: new AMap.Pixel(00, -30),
			 size:new AMap.Size(230,0)
		});
		//直接根据经度和纬度打开窗口
		infowindow.open(this.map,new AMap.LngLat(gd,wd));
	},
	clear:function(){//清楚覆盖物
		this.map.clearMap();
	},
	bus:function(stLon,stLat,desLon,desLat){
			$("#panel").html('');
			infowindow.close();
			var transOptions = {
		        map: this.map,
		        city:city,
		        panel: 'panel',                            
		        policy: AMap.TransferPolicy.LEAST_TIME
		    };
		    //构造公交换乘类
		    var transfer = new AMap.Transfer(transOptions);
		    //根据起、终点坐标查询公交换乘路线
		    transfer.search(new AMap.LngLat(stLon,stLat), new AMap.LngLat(desLon, desLat), function(status, result) {
		        // result即是对应的公交路线数据信息，相关数据结构文档请参考  https://lbs.amap.com/api/javascript-api/reference/route-search#m_TransferResult
		        if (status === 'complete') {
		        	console.log('绘制公交路线完成')
		        	$("#panel").css("background-image","url('https://ss3.baidu.com/-rVXeDTa2gU2pMbgoY3K/it/u=291877212,1756170074&fm=202&mola=new&crop=v1')");
		        } else {
		        	console.log('公交路线数据查询失败' + result)
		        }
		    });
	}
	


	//单独图片的切换标记
	/*marker2:function(gd,wd,icon){
		var marker = new AMap.Marker();
		marker.setMap(map);
		marker.setIcon(new AMap.Icon({            
		size: new AMap.Size(40, 50),  //图标大小
			image: "http://webapi.amap.com/theme/v1.3/images/newpc/"+icon+".png",
			imageOffset: new AMap.Pixel(0, -60)
		}));
		marker.setPosition([gd, wd]);
	},*/
	
};

function  getStar(num){
	
}


function tzMapPay(obj){
	var opts = {payType:"ali"};
	tzPay.pay(opts);
}
